package handler.accountFormHandlers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

import db.Account;
import db.DBConnector;
import other.AssetRegistryFrame;
import other.MenuUI;
import form.AccountForm.AccountForm;


public class LoginSubmitButtonActionListener implements ActionListener {

	AccountForm loginForm;
    DBConnector db;
	
	public LoginSubmitButtonActionListener(AccountForm loginForm){
		this.loginForm = loginForm;
		db = new DBConnector();
	}
	
	public void actionPerformed(ActionEvent e) {
		
		Account account = Account.createAccount(loginForm.getUserName().getInput());
		
		if(account != null  && loginForm.getUserName().hasValidInput() && loginForm.getPassword().hasValidInput() && account.getPassword().compareTo(loginForm.getPassword().getInput()) == 0){
			AssetRegistryFrame.getARFrame().changePanel(new MenuUI(account));
		}
		else
			JOptionPane.showMessageDialog(null,"Incorrect Username or Password.", "Error!", JOptionPane.WARNING_MESSAGE); 
	}

}
